package top.roadvast.activiti;

import org.activiti.engine.ProcessEngine;
import org.activiti.engine.ProcessEngines;
import org.activiti.engine.TaskService;
import org.activiti.engine.task.IdentityLink;
import org.junit.Test;

import java.util.HashSet;
import java.util.List;
import java.util.Set;

/**
 * @Author 郭泽鹏
 * @Date 2022/3/26 9:09
 * @Version 1.0
 * @Description 查询任务候选人
 */
public class TaskCandidateQuery {

    @Test
    public void test() {
        Set<String> users = new HashSet<>();
        String taskId = "5002";
        final ProcessEngine defaultProcessEngine = ProcessEngines.getDefaultProcessEngine();
        final TaskService taskService = defaultProcessEngine.getTaskService();
        final List<IdentityLink> identityLinkList = taskService.getIdentityLinksForTask(taskId);
        if (identityLinkList != null && identityLinkList.size() > 0) {
            for (IdentityLink identityLink : identityLinkList) {
                if (identityLink.getUserId() != null) {
                    users.add(identityLink.getUserId());
                }
            }
        }
        System.out.println(users);
    }
}
